<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
   <script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>

<div class="panel" style="height: 610px; overflow: auto;">
	<div class="panel-body pan" style="margin-left: 22px; margin-top: 50px;">
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">授权用户<span
				class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="organizationUserZh" type="text" placeholder="请选择用户" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
						<button id="xuanze" onclick="saveMember()" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="organizationUserid" type="hidden" value=""  class="form-control" />
					</div>
				</div>
			</div>
			<!-- <div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">项目名称
					<span class='require'>*</span></label>
				<div class="col-md-9">
					<div class="input-icon">
						<select class="form-control" id="projectId" name="projectName">
							  <option value=''>请先选择用户</option>
						
						</select>
					</div>
				</div>
			</div> -->
		</div>
		<div class="row" style="margin-bottom: 10px;height:750px;" >
			<div class="col-lg-6" style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">数据分析专题<span
				class='require'>*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs" id="multplediv">
						
					</div>
				</div>
			</div>
		
			<!--<div class="col-xs-8" style="padding-left:30px;" id="multplediv">
				 <input type="checkbox" value="">
				<input type="checkbox" value="">
				<input type="checkbox" value="">
				<input type="checkbox" value=""> 
			</div>-->
		</div>
		</div>
	</div>
</div>
<?} ?>

<script>
	var index1 = window.parent.getlay();
	$(function(){
		loadAnalysis();
		if(index1 !=0){
			$.ajax({
			type : "post",
			url : "jurisdictionQueryId.do",
			data : {
				'id':index1
			},
			dataType : "json",
			async : false,
			traditional : true,
			success : function(data) {
				if(data[0].msg=="OK"){
					$("#organizationUserZh").val(data[0].data.memberName);
					$("#organizationUserid").val(data[0].data.memberId);
					document.getElementById('xuanze').disabled = true;
					var special = data[0].data.specialId.split(";");
					var obj=document.getElementsByName('special'); 
					for(var i=0; i<obj.length; i++){ 
						for(var j = 0;j <special.length;j++){
							if(obj[i].value == special[j]){
								obj[i].checked = true;
							}
						}
					} 
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		})
		}
	})
	//选择机构
	function saveMember(){
		parent.layer.open({
			type : 2,
			area : [ '900px', '700px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"授权用户列表",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["analysis-jurisdiction-configuration-user.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  	iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	
	}
	
	/*加载专题管理*/
	function loadAnalysis(){
		$.ajax({
			type : "post",
			url : "analysisAll.do",
			data : {},
			dataType : "json",
			async : false,
			traditional : true,
			success : function(data) {
				if(data[0].msg=="OK"){
					var content = "";
					for(var i=0;i<data[0].data.length;i++){
						content += '<input type="checkbox" name="special" value="'+data[0].data[i].id+'">&nbsp;'+data[0].data[i].nameZh+'&nbsp;&nbsp;';
					}
					$("#multplediv").html(content);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		})
	}
	
	
		
	//添加
	function save() {
		var obj=document.getElementsByName('special'); 
		var s = "" ;
		for(var i=0; i<obj.length; i++){ 
			if(obj[i].checked){ 
				s+=obj[i].value+';';
			}
		} 
		
		if($.trim($("#organizationUserid").val()).length<1){
			alert("请选择要授权的用户");
			return null;
		}
		if(s == ""){
			alert("请选择要分析的专题");
			return null;
		}
		$.ajax({
			type : "post",
			url : "saveJurisdiction.do",
			data : {
				"id":index1,
				"organizationUserid" : $("#organizationUserid").val(),
				"special" : s
			},
			dataType : "json",
			async : false,
			traditional : true,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.demo(1);
				parent.layer.msg('新增成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	 
</script>
